﻿using LuckyLoot.ServiceFacade.Implementation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using LuckyLoot.Domain.Entities.People;
using LuckyLoot.Domain.ValueObjects;
using LuckyLoot.Common.Contexts;
using LuckyLoot.Common;

namespace LuckyLoot.ServiceFacadeTests
{
    
    
    /// <summary>
    ///This is a test class for UserServiceTest and is intended
    ///to contain all UserServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class UserServiceTest
    {
        private string _userName = "UNIT_TEST_USER";
        private string _tattooArtistUserName = "UNIT_TEST_TATTOO_ARTIST_USER";

        /// <summary>
        ///A test for UserService Constructor
        ///</summary>
        [TestMethod()]
        public void UserServiceConstructorTest()
        {
            UserService target = new UserService();
            Assert.IsNotNull(target);
        }

        /// <summary>
        ///A test for AddUser
        ///</summary>
        [TestMethod()]
        public void AddUserTest()
        {
            UserService userService = new UserService();
            User user = new User();
            user.Name = _userName;
            user.Email = string.Format("{0}{1}@{0}.com", _userName, DateTime.Now.Ticks);
            user.Password = "UNIT_TEST_PASSWORD";

            var savedUser = userService.AddUser(user);

            Assert.IsFalse(savedUser.Id <= 0);
        }

        /// <summary>
        ///A test for ChangePassword
        ///</summary>
        [TestMethod()]
        public void ChangePasswordTest()
        {
            UserService userService = new UserService();

            User user = new TattooArtist();
            user.Name = _tattooArtistUserName;
            user.Email = string.Format("{0}{1}@{0}.com", _tattooArtistUserName, DateTime.Now.Ticks);
            user.Password = "zeca";

            var savedUser = userService.AddUser(user);

            Assert.IsFalse(savedUser.Id <= 0);

            Password currentPassword = "zeca"; 
            Password newPassword = "acez";
            var changedPasswordUser = userService.ChangePassword(savedUser, currentPassword, newPassword);

            Assert.IsTrue(changedPasswordUser.Password.Match(Cryptography.Encrypt("acez")));
        }
    }
}
